home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Compression / StuffIt InstallerMaker™ Folder / InstallerMaker Extensions / IEnd Extension / undoFol.IEnd.c next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  4.4 KB  |  173 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3. The following source text is provided for the benefit of customers of
  4. Aladdin Systems, Inc., who wish to create custom Product Installers that
  5. incorporate functions similar to, but not exactly the same as, the undoFolder
  6. code resource that we supply on the StuffIt Installer Licensee disk.
  7.  
  8. If you are a licensee of our installation products, you may call Aladdin for technical
  9. support with this source code. Please contact Aladdin Developer Technical Support
  10. at (408) 761-6200. To license Aladdin installation technology, please contact
  11. Developer Product Licensing at the same telephone number. Or you can FAX us at
  12. (408) 761-6206.
  13.  
  14. */
  15.  
  16. #include <MacHeaders>
  17.  
  18.  
  19. //        IEnd.c        By Raymond Lau.
  20. //                    
  21. //        Copyright © 1992-93 Aladdin Systems, Inc. & Raymond Lau.
  22. //        All Rights Reserved.
  23. //        
  24. //        This source text produces an IEnd code-resource, which can
  25. //        be called by a Product Installer at the end of the installation
  26. //        process.  Specifications for IBeg, IMid, and IEnd code resources
  27. //        are given in the documentation for the StuffIt Installer™.
  28. //        
  29. //        This subroutine performs the following functions:
  30. //           
  31. //        • Move everything within the user-specified destination folder
  32. //          into the parent of that folder (i.e., one level up).
  33. //        • If an item cannot be moved to the parent directory because
  34. //          another item there already has the same name, then rename the
  35. //          item to be moved, before actually moving it.
  36. //        • Finally, delete the emptied user-specified folder.
  37. //        
  38. //        CHANGE HISTORY:
  39. //        
  40. //        VER    DATE        ENGR    DESCRIPTION
  41. //        1    93.04.14    rl        Initial version, some commentary added
  42. //                                by Jim Merritt (jam).
  43. //        2    94.03.14    jam        Modified main to observe new packages
  44. //                                parameter.
  45. //
  46. //        3    94.05.05    rmt        Rendered into ANSI C for Symantec C 6.0
  47. //                                by Robert Thorne (rmt)
  48. //
  49. //
  50. //
  51. //
  52.  
  53. typedef unsigned char uchar;
  54.  
  55. // Function Prototype
  56. uchar *pstrcat (uchar *s1, uchar *s2) ;
  57.  
  58.  
  59. /*
  60.     Concatenate the pascal string "s2" onto the end of the current
  61.     contents of the pascal string "s1".  Returns "s1".
  62. */
  63.  
  64.  
  65. uchar *pstrcat (uchar *s1, uchar *s2)
  66. {
  67.     short i;
  68.  
  69.     for (i = 1; i <= s2 [0]; ++i)
  70.         s1 [++s1 [0]] = s2 [i];
  71.  
  72.     return (s1);
  73. }
  74.  
  75.  
  76. pascal short main(short abort,short vol,long dir,uchar *name,
  77.                   unsigned short packages)
  78.  
  79. {    if(!abort) {
  80.         HParamBlockRec HRec;
  81.  
  82.         HRec.ioParam.ioNamePtr = (StringPtr)name;
  83.         HRec.ioParam.ioVRefNum = vol;
  84.         HRec.fileParam.ioDirID = dir;
  85.         HRec.fileParam.ioFDirIndex = 0;
  86.         
  87.         if(PBGetCatInfoSync((CInfoPBPtr)&HRec)) {
  88.             // really weird!  Nothing got unstuffed?
  89.             abort = TRUE;
  90.         } else {
  91.             long sourcedir = HRec.fileParam.ioDirID;
  92.             short i;
  93.             
  94.             if(!(HRec.fileParam.ioFlAttrib & 0x10))
  95.                 goto out;
  96.                 
  97.             i = 1;
  98.             for(;;) {
  99.                 short j;
  100.                 uchar str[10],newname[32],sourcename[32];
  101.                 CMovePBRec cmpb;
  102.  
  103.                 HRec.fileParam.ioFDirIndex = 1;
  104.                 HRec.fileParam.ioDirID = sourcedir;
  105.                 HRec.fileParam.ioVRefNum = vol;
  106.                 HRec.fileParam.ioNamePtr = sourcename;
  107.                 
  108.                 if(PBGetCatInfoSync((CInfoPBPtr)&HRec))
  109.                     break;
  110.                 
  111.                 j = 0;
  112.                     
  113.                 for(;;) {
  114.                     // see if it exists in the level above.
  115.                     BlockMove(sourcename,newname,32);
  116.                     if(j) {
  117.                         if(newname[0] > 28)
  118.                             newname[0] = 28;
  119.                         NumToString(j,str);
  120.                         pstrcat(newname,"\p.");
  121.                         pstrcat(newname,str);
  122.                     }
  123.                     HRec.fileParam.ioFDirIndex = 0;
  124.                     HRec.fileParam.ioDirID = dir;
  125.                     HRec.fileParam.ioVRefNum = vol;
  126.                     HRec.fileParam.ioNamePtr = newname;
  127.                     
  128.                     if(PBGetCatInfoSync((CInfoPBPtr)&HRec) == fnfErr) {
  129.                         if(!j)
  130.                             break;
  131.                         
  132.                         // hrumph -- check current level as well.
  133.                         HRec.fileParam.ioFDirIndex = 0;
  134.                         HRec.fileParam.ioDirID = sourcedir;
  135.                         HRec.fileParam.ioVRefNum = vol;
  136.                         HRec.fileParam.ioNamePtr = newname;
  137.                         
  138.                         if(PBGetCatInfoSync((CInfoPBPtr)&HRec) == fnfErr)
  139.                             break;
  140.                     }
  141.                     
  142.                     j++;
  143.                 }
  144.                 
  145.                 if(j) {
  146.                     HRec.fileParam.ioDirID = sourcedir;
  147.                     HRec.fileParam.ioVRefNum = vol;
  148.                     HRec.fileParam.ioNamePtr = (StringPtr)sourcename;
  149.                     HRec.ioParam.ioMisc = (Ptr)newname;
  150.                     PBHRenameSync(&HRec);
  151.                 }
  152.                 
  153.                 cmpb.ioNamePtr = (StringPtr)newname;
  154.                 cmpb.ioVRefNum = vol;
  155.                 cmpb.ioNewName = (StringPtr)0L;
  156.                 cmpb.ioNewDirID = dir;
  157.                 cmpb.ioDirID = sourcedir;
  158.                 
  159.                 PBCatMoveSync(&cmpb);
  160.             }
  161.             
  162.             // now delete the folder
  163.             HRec.ioParam.ioNamePtr = (StringPtr)name;
  164.             HRec.ioParam.ioVRefNum = vol;
  165.             HRec.fileParam.ioDirID = dir;
  166.             PBHDeleteSync(&HRec);
  167.         }
  168.     }
  169.  
  170. out:
  171.     return abort;
  172. }
  173.